<template>
  <div class="good-detail wap">
    <x-header  v-if="!this.$fromApp(this)" :left-options="{backText: ''}"><span>商品详情</span></x-header>
    <div class="main">

      <scroller
        ref="scroll"
      >
        <div class="swiper-container" v-if="goodInfo.pics">
          <swiper @click.native="showPic" height="320px" :show-dots="false" loop :list="goodInfo.pics"
                  @on-index-change="swiperIndexChange"></swiper>
          <div class="page-index display-flex justify-content-flex-center align-items-center">
            <span class="active">{{imgIndex+1}}</span><span class="total">/{{goodInfo.pics.length}}</span>
          </div>
        </div>

        <div class="cell  vux-1px-b display-flex align-items-center">
          <div class="lable">商品名称:</div>
          <div class="value">{{goodInfo.name}}</div>
        </div>
        <div class="cell  vux-1px-b display-flex align-items-center">
          <div class="lable">品牌:</div>
          <div class="value">{{goodInfo.brandName}}</div>
        </div>
        <div class="cell  vux-1px-b display-flex align-items-center">
          <div class="lable">单位:</div>
          <div class="value display-flex">
            <div class="display-flex align-items-center">
            <span>
              <i :class="['iconfont','unit-radio',goodInfo.rate==1?'icon-radioactive unit-radio-active':'icon-radio']"></i><span class="unit">件</span></span>
              <i :class="['iconfont','unit-radio',goodInfo.rate!=1?'icon-radioactive unit-radio-active':'icon-radio']"></i>
            </div>
            <div class="flex-1 display-flex align-items-center">
              <span class="num display-flex justify-content-flex-center align-items-center">{{goodInfo.rate!=1?goodInfo.rate:''}}</span>
              <span class="num-unit">包/件</span>
            </div>
          </div>
        </div>

        <div class="cell  vux-1px-b display-flex align-items-center">
          <div class="lable">编号:</div>
          <div class="value">{{goodInfo.code}}</div>
        </div>

        <div class="cell  vux-1px-b display-flex align-items-center">
          <div class="lable">商品分类:</div>
          <div class="value">{{goodInfo.goodsCategoryName}}</div>
        </div>

        <div class="cell  vux-1px-b display-flex align-items-center">
          <div class="lable">规格:</div>
          <div class="value display-flex align-items-center">
            <span class="spec">{{goodInfo.specNum}}</span>
            <span class="spec-lable">kg/{{goodInfo.rate==1?'件':'包'}}</span>
          </div>
        </div>

        <div class="cell  vux-1px-b display-flex align-items-center">
          <div class="lable">毛重:</div>
          <div class="value display-flex align-items-center">
            <span class="spec">{{goodInfo.weight}}</span>
            <span class="spec-lable">kg/件</span>
          </div>
        </div>


        <div class="cell  vux-1px-b display-flex align-items-center">
          <div class="lable">商品尺寸:</div>
          <div class="value display-flex align-items-center">
            <span class="spec-w">{{goodInfo.sizeLength}}</span>
            <span class="spec-symbol">*</span>
            <span class="spec-w">{{goodInfo.sizeWidth}}</span>
            <span class="spec-symbol">*</span>
            <span class="spec-w display-flex justify-content-flex-center align-items-center">{{goodInfo.sizeHeight}}</span>
            <span class="good-spec-unit">mm</span>
          </div>
        </div>

        <div class="cell  vux-1px-b display-flex align-items-center">
          <div class="lable">保质期:</div>
          <div class="value display-flex align-items-center">
            <span class="spec display-flex justify-content-flex-center align-items-center">{{goodInfo.shelfLife}}</span>
            <span class="spec-lable">天</span>
          </div>
        </div>

        <div class="cell  vux-1px-b display-flex align-items-center">
          <div class="lable">生产厂家:</div>
          <div class="value">{{goodInfo.factory}}</div>
        </div>


        <div class="cell  vux-1px-b display-flex align-items-center">
          <div class="lable">原产地:</div>
          <div class="value">{{goodInfo.originArea}}</div>
        </div>
        <div class="cell  vux-1px-b display-flex align-items-center">
          <div class="lable">加工方式:</div>
          <div class="value">{{goodInfo.processMethod}}</div>
        </div>
        <div class="cell  vux-1px-b display-flex align-items-center">
          <div class="lable">储存方法:</div>
          <div class="value">{{goodInfo.store}}</div>
        </div>

        <div class="cell  vux-1px-b display-flex align-items-center">
        <div class="lable">商品条码:</div>
        <div class="value">{{goodInfo.barCode}}</div>
      </div>
        <!--<div class="cell  vux-1px-b display-flex align-items-center">-->
          <!--<div class="lable">商品编号:</div>-->
          <!--<div class="value">{{goodInfo.code}}</div>-->
        <!--</div>-->

        <div class="cell  vux-1px-b display-flex align-items-center">
          <div class="lable">QS号:</div>
          <div class="value">{{goodInfo.qs}}</div>
        </div>


        <div class="cell  vux-1px-b display-flex align-items-center">
          <div class="lable">流通许可证:</div>
          <div class="value">{{goodInfo.flowLicense}}</div>
        </div>

        <div class="cell  vux-1px-b display-flex align-items-center">
          <div class="lable">商品明细:</div>
          <div class="value" v-html="goodInfo.detail"></div>
        </div>

        <div class="cell  vux-1px-b display-flex align-items-center">
          <div class="lable">商品描述:</div>
          <div class="value" v-html="goodInfo.memo"></div>
        </div>



        <div class="footer display-flex align-items-center justify-content-flex-center">
          <div class="btn-comfirm display-flex justify-content-flex-center align-items-center" @click="goBack"><span >知道了</span></div>

        </div>
      </scroller>
    </div>

    <imgPreview v-if="goodInfo.pics" :picList="goodInfo.pics"  ref="preview"></imgPreview>
  </div>
</template>
<script type="text/ecmascript-6">
  import  imgPreview from  '../../components/img-preview.vue'
  export default {
    components:{
      imgPreview
    },
    data() {
      return {
        demo1: false,
        imgIndex: 0,
        goodInfo:{}
      }
    },
    created(){
      if(this.$route.query.type==1){
        this.initData();
      }else{
        this.initGoodInfo();
      }
    },
    methods: {
      initGoodInfo(){
        this.$ajax.get("goods/detail",(res)=>{
          console.log("====res",res);
          if(res.code==200){
            this.goodInfo=res.data;
            for(let i=0;i<res.data.pics.length;i++){
              this.goodInfo.pics[i]={img:res.data.pics[i]}
            }

          }else{
            this.$vux.toast.text(res.msg, 'center');
          }
        },{goodsId:this.$route.query.id})
      },
      initData(){
           this.$ajax.get("goods/template/detail",(res)=>{
            console.log("====res",res);
             if(res.code==200){
               this.goodInfo=res.data;
               for(let i=0;i<res.data.pics.length;i++){
                 this.goodInfo.pics[i]={img:res.data.pics[i]}
               }

             }else{
               this.$vux.toast.text(res.msg, 'center');
             }
          },{templateId:this.$route.query.id})
      },
      swiperIndexChange(index) {
        this.imgIndex = index;
      },
      showPic(){
        this.$refs.preview.show(this.imgIndex);
      },
      goBack(){
        if(this.$fromApp(this)){
          this.$callJava({code:1007})
        }else{
          this.$router.go(-1);//返回上一层
        }

      }
    }
  }
</script>

<style lang="less" type="text/less" scoped>
  .good-detail {
    background: #fff;
    .swiper-container {
      position: relative;
      .page-index {
        position: absolute;
        bottom: .24rem;
        right: .3rem;
        background: #cbcbcb;
        border-radius: .2rem;
        height: .4rem;
        padding: 0 .2rem;
        .active {
          font-size: .28rem;
          color: #222;
          font-weight: bold;
        }
        .total {
          font-size: .20rem;
          color: #666;
        }
      }
      /deep/ .vux-slider > .vux-swiper > .vux-swiper-item > a > .vux-swiper-desc {
        height: 0;
        background-image: none;
        padding: 0;
      }
      /deep/ .vux-slider > .vux-swiper > .vux-swiper-item > a > .vux-img{
        background-size: 100% 100%!important;

      }
    }
    .cell {
      padding: 0 .3rem;
      min-height: 1.02rem;
      .lable {
        min-width: 1.5rem;
        color: #222;
        font-size: .32rem;
        font-weight: 500;
      }
      .value {
        padding: .1rem 0;
        margin-left: .7rem;
        font-weight: 500;
        font-size: .32rem;
      }
      .unit {
        vertical-align: middle;
        margin-right: .6rem;
        font-size: .32rem;
      }
      .unit-radio {
        font-size: 30px;
        color: #ddd;
        vertical-align: middle;
      }
      .unit-radio-active {
        color: #527DD9;
      }
      .num {
        text-align: center;
        margin-left: .24rem;
        background: #f1f1f1;
        min-width: .9rem;
        min-height: .64rem;
        text-align: left;
        padding: 0 .2rem;
        box-sizing: border-box;
      }
      .num-unit {
        color: #333;
        font-size: .32rem;
        margin-left: .2rem;
      }
      .spec {
        background: #f1f1f1;
        min-width: 2rem;
        min-height: .64rem;
        text-align: left;
        padding: 0 .2rem;
        box-sizing: border-box;
      }
      .spec-lable {
        margin-left: .3rem;
        font-size: .32rem;
        color: #333;
      }
      .spec-w {
        background: #f1f1f1;
        min-width: .94rem;
        min-height: .64rem;
        text-align: left;
        padding: 0 .2rem;
        box-sizing: border-box;
      }
      .spec-symbol {
        margin: 0 .12rem;
        color: #333;
        font-size: .32rem;
      }
      .good-spec-unit {
        margin-left: .1rem;
        color: #333;
        font-size: .32rem;
      }
    }
    .detail {
      margin-top: .2rem;
      background: #fff;
      padding: .3rem .3rem;
      .title {
        font-size: .3rem;
        color: #333;
        margin-bottom: .6rem;
      }
      .vux-table{
        line-height: normal;
      }
      .vux-table td, .vux-table th {
        text-align: left;
        padding-left: .25rem;
        padding: .2rem;
      }
      .label {
        font-size: .26rem;
        color: #999;
        margin-right: .25rem;
      }
      .content {
        font-size: .26rem;
        color: #222;
        margin-right: .2rem;
      }
      .html-content {
        margin-top: .4rem;
      }
    }

    .footer {
      text-align: center;
      .btn-comfirm {
        margin: .6rem 0 .28rem 0;
        min-width: 3.26rem;
        height: .84rem;
        background: rgba(82, 125, 217, 0);
        border: 1px solid rgba(221, 221, 221, 1);
        border-radius: .42rem;
        color: #333;
        font-size: .34rem;
      }
    }
  }
</style>
